package com.arvato.minipro.bean.bean_dto.common;
/**
 * 封装和界面交互的数据的类
 * @author smallking
 *
 */
public class Result {

	private Integer code;
	
	private String msg;
	
	private Object data;
	
	public Result(){
		
	}
	
	public Result(boolean flag){
		if(flag == false){
			this.code = 500;
			this.msg = "操作失败，请稍后再试。";
		}else{
			this.code = 200;
			this.msg = "操作成功。";
		}
	}
	public Result(boolean flag, Object data){
		if(flag == false){
			this.code = 500;
			this.msg = "操作失败，请稍后再试。";
		}else{
			this.code = 200;
			this.msg = "操作成功。";
		}
		this.data = data;
	}
	public Result(boolean flag, String msg, Object data) {
		if(flag == false){
			this.code = 500;
		}else{
			this.code = 200;
		}
		this.data = data;
		this.msg = msg;
	}
	public void setResult(boolean flag){
		if(flag == false){
			this.code = 500;
			this.msg = "操作失败，请稍后再试。";
		}else{
			this.code = 200;
			this.msg = "操作成功。";
		}
	}
	
	
	public Integer getCode() {
		return code;
	}
	public void setCode(Integer code) {
		this.code = code;
	}
	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}
	
	public static Result success() {
		return new Result(true, null);
	}
	
	public static Result success(Object data) {
		return new Result(true, data);
	}
	public static Result success(String msg, Object data) {
		return new Result(true, msg, data);
	}
	
	public static Result fail() {
		return new Result(false, null, null);
	}
	
	public static Result fail(String msg, Object data) {
		return new Result(false, msg, data);
	}
	
	public static Result fail(String msg) {
		return new Result(false, msg, null);
	}
	
	public static Result fail(Object data) {
		return new Result(false, "", data);
	}
	@Override
	public String toString() {
		return "Result [code=" + code + ", msg=" + msg + ", data=" + data + "]";
	}
	
}
